<?php

namespace App\Admin\Forms;

use App\Admin\Field\HospitalAppointMonthField;
use Dcat\Admin\Widgets\Form;
use App\Admin\Field\IntervalWeekNum;
use App\Models\HospitalAppointInterval;
use App\Models\HospitalAppointIntervalNum;
use App\Models\HospitalAppointMonth;
use App\Models\HospitalAppointStreet;
use App\Models\Street;
use Illuminate\Support\Facades\DB;

class HospitalAppointMonthForm extends Form
{
    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    public function handle(array $input)
    {
        $hospital_appoint_id = $input['hospital_appoint_id'];
        $hospital_id = $input['hospital_id'];

        $model = HospitalAppointMonth::query()
        ->where('hospital_id',$hospital_id)
        ->where('hospital_appoint_id',$hospital_appoint_id)
        ->first();
        if(!$model){
            $model = new HospitalAppointMonth();
        }
        $model->hospital_id = $hospital_id;
        $model->hospital_appoint_id = $hospital_appoint_id;
        $model->month = $input['month'];
        $model->save();

        return $this->response()->success('成功');
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        \Dcat\Admin\Form::extend('month',HospitalAppointMonthField::class);

        $this->month('month');
        $this->hidden('hospital_appoint_id');
        $this->hidden('hospital_id');

    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        return [
            'name'  => 'John Doe',
            'email' => 'John.Doe@gmail.com',
        ];
    }
}
